<template>
  <div style="background: #f7f7f7">
    <div class="swiper-wrapper">
      <el-carousel >
        <el-carousel-item v-for="(item, index) in swiperList" :key="index">
          <img :src="item.bannerImg | formatFile" />
        </el-carousel-item>
      </el-carousel>
    </div>

    <div class="index-navs flex-x-bet-y-center">
      <div class="nav-item" v-for="(item, index) in navsList" :key="index" @click="toProductList(item)">
        <div class="left-bg" :style="'background-image: url(' + item.bg + ')'">
          <div class="nav-name">{{ item.name }}</div>
          <div class="navigator-btn flex-xy-center">
            <span :style="{ color: item.color }">立即查看</span>
            <img :src="item.arrow" alt="" />
          </div>
        </div>
        <div class="right-wrapper flex-1 flex-xy-center">
          <img :src="item.car" alt="" />
        </div>
      </div>
    </div>

    <div class="list-title flex-x-bet-y-center">
      <div class="title">最新需求</div>
      <div class="more flex-y-center" @click="toDemandList">
        <span>查看更多</span>
        <img src="@/assets/img/arrow-right1.png" alt="" />
      </div>
    </div>

    <div class="demand-list">
      <div class="demand-item" v-for="(item, index) in newDemandList" :key="index" @click="toDemandDetail">
        <div class="title">{{ item.demandTitle }}</div>
        <div class="content">
          {{ item.intro }}
        </div>
        <div class="date">发布时间：{{ item.createTime }}</div>
      </div>
    </div>

    <div class="list-title flex-x-bet-y-center">
      <div class="title">推荐店铺</div>
      <div class="more flex-y-center" @click="toStoreList">
        <span>查看更多</span>
        <img src="@/assets/img/arrow-right1.png" alt="" />
      </div>
    </div>

    <div class="store-list">
      <div class="store-item" v-for="(item, index) in storeList" :key="index" @click="toStoreDetail">
        <img :src="item.firmImgs.split(',')[0] | formatFile" class="cover" alt="" />
        <div class="bottom-info">
          <div class="name">{{item.firmName}}</div>
          <div class="desc">{{item.mainBusiness}}</div>
          <div class="desc">{{item.province}}{{item.city}}{{item.area}}</div>
        </div>
      </div>
    </div>

    <div class="list-title flex-x-bet-y-center">
      <div class="title2 flex-y-center">
        <img src="@/assets/img/icon-hot.png" alt="" class="icon-hot">
        <span>热门商品</span>        
      </div>
    </div>

    <div class="product-list">
        <ProductItem v-for="(item, index) in 6" :key="index"></ProductItem>
    </div>
  </div>
</template>

<script>
import ProductItem from "@/components/ProductItem.vue";
import { getBanner } from '@/api/common'
import { indexNewDemand } from '@/api/demand'
import { recommendStore } from '@/api/store'
export default {
  name: "Index",
  components: {
    ProductItem,
  },
  data() {
    return {
      swiperList: [],
      newDemandList: [],
      navsList: [
        {
          name: "厂家货源",
          color: "#F97D4A",
          bg: require("@/assets/img/bg-nav1.png"),
          arrow: require("@/assets/img/arrow-right.png"),
          car: require("@/assets/img/index-car1.png"),
          url:'/productList/factory'
        },
        {
          name: "二手货源",
          color: "#F4AC62",
          bg: require("@/assets/img/bg-nav2.png"),
          arrow: require("@/assets/img/arrow-right2.png"),
          car: require("@/assets/img/index-car2.png"),
          url:'/productList/used'
        },
        {
          name: "租赁货源",
          color: "#43B1AE",
          bg: require("@/assets/img/bg-nav3.png"),
          arrow: require("@/assets/img/arrow-right3.png"),
          car: require("@/assets/img/index-car3.png"),
          url:'/productList/rentOut'
        },
      ],
      storeList:[]
    };
  },
  created(){
    this.$bus.$emit('showBreadCrumb', true)
    this.getBanner()
    this.indexNewDemand()
    this.recommendStore()
  },
  methods: {
    getBanner(){
      getBanner({platformType: 1, bannerPosition: 1}).then(res => {
        this.swiperList = res.result
      })
    },
    recommendStore(){
      recommendStore().then(res => {
        this.storeList = res.result
      })
    },
    indexNewDemand(){
        indexNewDemand({}).then(res => {
					this.newDemandList = res.result
				})
    },
    toProductList(item){
      this.$router.push(item.url)
    },
    toDemandDetail(){
      this.$router.push('/demandDetail/Index')
    },
    toDemandList(){
      this.$router.push('/demandHall')
    },
    toStoreList(){
      this.$router.push('/storeList/Index')
    },
    toStoreDetail(){
      this.$router.push('/storeDetail/Index')
    }
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-carousel__container {
  width: 100%;
  height: 700px !important;
}

::v-deep .el-carousel{
  height: 700px !important;
}

::v-deep .el-carousel__item{
  height: 700px !important;
}

.swiper-wrapper {
  width: 100%;
  height: 700px;

  img {
    width: 100%;
    height: 100%;
  }
}

.index-navs {
  width: 1200px;
  margin: 30px auto 0;

  .nav-item {
    display: flex;
    overflow: hidden;
    width: 386px;
    height: 220px;
    background: #ffffff;
    border-radius: 8px;
    cursor: pointer;
  }

  .left-bg {
    height: 100%;
    width: 128px;
    background-size: 100% 100%;;

    .nav-name {
      text-align: center;
      padding-top: 30px;
      font-weight: bold;
      font-size: 20px;
      color: #ffffff;
      text-shadow: 0px 1px 2px rgba(250, 126, 72, 0.51);
    }

    .navigator-btn {
      width: 86px;
      height: 28px;
      background: #ffffff;
      border-radius: 6px;
      font-size: 16px;
      margin: 15px auto;

      img {
        width: 16px;
        height: 16px;
      }
    }
  }

  .right-wrapper {
    img {
      width: 216px;
      height: 216px;
    }
  }
}

.list-title {
  width: 1200px;
  padding: 30px 0;
  margin: 0 auto;
  box-sizing: border-box;

  .title,
  .title2 {
    position: relative;
    font-weight: 800;
    font-size: 20px;
    color: #333333;
    padding-left: 16px;
  }
  
  .icon-hot{
    width: 26px;
    height: 26px;
    margin-right: 10px;
  }

  .title::before {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    content: "";
    width: 6px;
    height: 20px;
    background: #fe5a13;
  }

  .more {
    font-weight: 500;
    font-size: 16px;
    color: #808080;
    cursor: pointer;

    img {
      position: relative;
      top: 2px;
      width: 16px;
      height: 16px;
      margin-left: 10px;
    }
  }
}

.demand-list {
  width: 1200px;
  margin: auto;

  .demand-item {
    background: #ffffff;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    cursor: pointer;

    .title {
      font-weight: 800;
      font-size: 18px;
      color: #333333;
    }

    .content {
      padding: 12px 0;
      font-weight: 500;
      font-size: 16px;
      color: #808080;
    }

    .date {
      font-weight: 500;
      font-size: 16px;
      color: #999999;
    }
  }

  .demand-item:last-child {
    margin: 0;
  }
}

.store-list,
.product-list {
  display: flex;
  width: 1200px;
  margin: auto;

  .store-item {
    display: flex;
    flex-direction: column;
    margin-right: 13px;
    width: 229px;
    box-sizing: border-box;

    .cover {
        width: 229px;
        height: 230px;
    }

    .bottom-info {
      background: #fff;
      padding: 15px 15px 0 15px;

      .name {
        font-weight: 400;
        font-size: 18px;
        color: #333333;
      }

      .desc {
        font-weight: 400;
        font-size: 16px;
        color: #808080;
        margin: 12px 0;
      }
    }
  }
}

.product-list{
    flex-wrap: wrap;

   ::v-deep .com-product-item:nth-of-type(5n){
        margin-right: 0;
    }

    ::v-deep .com-product-item{
        margin-bottom: 18px;
    }
}
</style>
